package cn.just.student_mall.config;

import cn.just.student_mall.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;

/**
 * @Author wujiaming
 * @Description TODO
 * @Date 2021-03-25 8:16
 * @Version 1.0
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //创建拦截器对象
        HandlerInterceptor interceptor = new LoginInterceptor();
        //在拦截器类中添加拦截器对象 ;配置除外路径
        //配置例外路径
        ArrayList<String> patterns = new ArrayList<>();
        patterns.add("/users/login");
        patterns.add("/users/reg");
        patterns.add("/web/register.html");
        patterns.add("/web/login.html");
        patterns.add("/bootstrap3/**");
        patterns.add("/images/**");
        patterns.add("/css/**");
        patterns.add("/js/**");
        registry.addInterceptor(interceptor).addPathPatterns("/**").excludePathPatterns(patterns);
    }
}
